package org.ctstudio.common.utils;

import java.beans.PropertyEditorSupport;
import java.time.LocalDate;

public class LocalDateEditor extends PropertyEditorSupport {

  public void setAsText(String text) throws IllegalArgumentException {
    if (text == null || text.length() == 0) {
      setValue(null);
    } else {
      setValue(LocalDate.parse(text));
    }
  }

  public String getAsText() {
    LocalDate value = (LocalDate) getValue();
    return value != null ? value.toString() : "";
  }
}
